﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Common {
    public class Screenshots {
        /// <summary>
        /// //截取全屏图象
        /// </summary>
        public void FullScreen(string filePath) {
            //创建图象，保存将来截取的图象
            Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
            Graphics imgGraphics = Graphics.FromImage(image);
            //设置截屏区域
            imgGraphics.CopyFromScreen(0,0,0,0,new Size(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height));
            //保存
            SaveImage(image,filePath);
        }

        //保存图象文件
        private void SaveImage(Image image,string filePath) {
            string extension = Path.GetExtension(filePath);
            if(extension == ".jpg") {
                image.Save(filePath,ImageFormat.Jpeg);
            } else {
                image.Save(filePath,ImageFormat.Bmp);
            }
        }
    }
}
